package com.example.shixun.service.impl;

import com.example.shixun.dao.PostDao;
import com.example.shixun.pojo.Post;
import com.example.shixun.service.PostService;
import com.example.shixun.utils.PageInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author XDW
 * @Version 1.0
 * @date 2023/6/24 16:09
 */
@Service
public class PostServiceImpl implements PostService {
    @Resource
    private PostDao postDao;

    @Override
    public int savePost(Post post) {
        return postDao.savePost(post);
    }

    @Override
    public int deletePostById(int id) {
        return postDao.deletePostById(id);
    }

    @Override
    public Post selectPostById(int id) {
        return postDao.selectPostById(id);
    }

    @Override
    public int updatePost(Post post) {
        return postDao.updatePost(post);
    }

    @Override
    public PageInfoUtil<Post> findAll(PageInfoUtil<Post> pageInfoUtil) {
        PageHelper.startPage(pageInfoUtil.getPageNum(), pageInfoUtil.getPageSize(), pageInfoUtil.getOrderBy());
        List<Post>  lists=postDao.findAll(pageInfoUtil.getParams());
        PageInfo<Post> pageInfo=new PageInfo<>(lists);
        pageInfoUtil.setPageTotal(pageInfo.getPages());
        pageInfoUtil.setTotal(pageInfo.getTotal());
        pageInfoUtil.setList(lists);
//        System.out.println(pageInfoUtil);
        return pageInfoUtil;
    }

    @Override
    public Integer addReplies(Integer id) {
        return postDao.addReplies(id);
    }
}
